<!--- 
	/* ******************************************************************************************************************************
	 * add application config options here 
	 * base is duplicated in other env.
	 * if a key (e.g. dsn, db) is found in the inheriting environments to other environments, their values will override base config.
	 * to append with "__" suffix (e.g. "abc__") in envs other than base
	 * ******************************************************************************************************************************
	 * Required Keys:
	 * base, current_env
	 * when environment changes, the current_env value should be changed accordingly
	 * ****************************************************************************************************************************** 
	 * Required fields:
	 * dsn, db, context
	 * ******************************************************************************************************************************
	 * When creating dir structure, remeber to escape with '\\'. For e.g. ("temp_dir":"E:\\temp")
	 * ******************************************************************************************************************************
	 */
--->
<cfcomponent>
	<cfset config.json = "" />
	<cffunction access="private" returntype="void" name="init">
		<cfset config.json = '{
			"env":{
				"base":{
					"dsn":"",
					"db":"",
					"admin":"anang.phatak@gmail.com",
					"temp_dir":"",
					"context":"cfturbine"
				},
				"dev":{
					
				},
				"qa":{
					
				},
				"uat":{
				
				},
				"production":{
					"admin__":"admin@domain.com"
				}
			},
			"current_env":"dev"
		}' />
	</cffunction>
	
	<cffunction access="public" returntype="Struct" name = "getConfig">
		<cfset init() />
		<cfset config = DeserializeJSON(config.json) />
		
		<cfloop collection="#config.env#" item="i">
			<cfif i NEQ "base">
				<cfif config.current_env  NEQ i>
					<cfset StructDelete(config.env, i) />
				<cfelse>
					<cfloop collection="#config.env.base#" item="j">
						<cfif StructKeyExists(config.env["#i#"], "#j#__")>
							<cfset config.env["#i#"]["#j#"] = listAppend(config.env["#i#"]["#j#__"], #config.env["base"][j]#) />
							<cfset StructDelete(config.env["#i#"], "#j#__")>
						</cfif>
						<cfif NOT StructKeyExists(config.env["#i#"], j)>
							<cfset config.env["#i#"]["#j#"] = #config.env["base"][j]# />
						</cfif>
					</cfloop>	
				</cfif>
			</cfif>
		</cfloop>
		
		<cfset StructDelete(config.env, "base") />
		
		<cfreturn config />
	</cffunction>
</cfcomponent>